home *** CD-ROM | disk | FTP | other *** search
/ Precision Software Appli…tions Silver Collection 1 / Precision Software Applications Silver Collection Volume One (PSM) (1993).iso / windows / games / burst2.arj / BURST2.C < prev    next >
Text File  |  1989-01-18  |  4KB  |  138 lines

  1. /***********************************************************************
  2.  * This program was originally written by Michael Harrison [76057,101] *
  3.  * I made the same modifications to this program as to burst and face. *
  4.  * Since this program only pops up the bitmap once, it doesn't suffer  *
  5.  * from the same problems the others did, but I made the changes as a  *
  6.  * matter of style.  That way, is the user wanted it to stay around,   *
  7.  * and recompiled it, it wouldn't hog memory when changed.             *
  8.  * Perri Nelson [71401,2116]                                           *
  9.  ***********************************************************************/
  10. #include <windows.h>
  11. #include <stdlib.h>
  12.  
  13. long FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  14. void FAR PASCAL TimerProc(HWND, unsigned, WORD, LONG);
  15.  
  16. HANDLE    hInst;
  17.  
  18.     /* Moved from WndProc to make available to WinMain as well */
  19.     static HANDLE hBitmap;
  20.  
  21. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  22.     HANDLE      hInstance, hPrevInstance;
  23.     LPSTR       lpszCmdLine;
  24.     int         nCmdShow;
  25.     {
  26.     HWND        hWnd;
  27.     MSG         msg;
  28.     WNDCLASS    wndclass;
  29.     FARPROC     lpfnTimerProc;
  30.  
  31.     if (!hPrevInstance)
  32.         {
  33.         wndclass.style          = CS_HREDRAW;
  34.         wndclass.lpfnWndProc    = WndProc;
  35.         wndclass.cbClsExtra     = 0;
  36.         wndclass.cbWndExtra     = 0;
  37.         wndclass.hInstance      = hInstance;
  38.         wndclass.hIcon          = NULL;
  39.         wndclass.hCursor        = LoadCursor (hInstance, IDC_ARROW);
  40.         wndclass.hbrBackground  = GetStockObject (WHITE_BRUSH);
  41.         wndclass.lpszMenuName   = NULL;
  42.         wndclass.lpszClassName  = "Burst2";
  43.  
  44.     if (!RegisterClass (&wndclass) )
  45.         return FALSE;
  46.         }
  47.     else
  48.         return FALSE;           /* only allow one instance */
  49.  
  50.  
  51.     hInst=hInstance;
  52.     hWnd = CreateWindow ("Burst2", "Burst2", WS_OVERLAPPEDWINDOW, 0, 0,
  53.                         0,0, NULL, NULL, hInstance, NULL);
  54.  
  55.  
  56.     /* wait one minute before doing anything */
  57.     if(!SetTimer(hWnd, 1, 60000+(rand()*10), NULL))
  58.         {
  59.         MessageBox(hWnd, "Too many clocks or timers!", "Burst2",
  60.                    MB_ICONEXCLAMATION | MB_OK);
  61.         return FALSE;
  62.         }
  63.  
  64.                 /* Moved from WndProc to improve memory usage */
  65.                 hBitmap=LoadBitmap(hInst, "Burst2");
  66.  
  67.     while (GetMessage(&msg, NULL, 0,0 ))
  68.         {
  69.         TranslateMessage(&msg);
  70.         DispatchMessage(&msg);
  71.         }
  72.     return msg.wParam;
  73.     }
  74.  
  75. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  76.     HWND          hWnd;
  77.     unsigned      iMessage;
  78.     WORD          wParam;
  79.     LONG          lParam;
  80.     {
  81.     BITMAP        bm;
  82.     HDC           hDC,hMemDC;
  83.     short         nRand;
  84.     long          xStart, yStart;
  85.     static char   cJunk=0;
  86.     unsigned int  nIndex;
  87.     static int    nNoise=0;
  88.  
  89.  
  90.     switch (iMessage)
  91.         {
  92.         case WM_TIMER:
  93.             if(rand() < 2000)
  94.                 {
  95.  
  96.                 GetObject(hBitmap, sizeof(BITMAP), (LPSTR) &bm);
  97.  
  98.                 hDC=CreateDC("DISPLAY", NULL, NULL, NULL);
  99.                 hMemDC=CreateCompatibleDC(hDC);
  100.                 SelectObject(hMemDC, hBitmap);
  101.  
  102.                 xStart= (GetSystemMetrics(SM_CXSCREEN)/2)-(bm.bmWidth/2);
  103.                 yStart= (GetSystemMetrics(SM_CYSCREEN)/2)-(bm.bmHeight/2);
  104.                 BitBlt(hDC, (short)xStart, (short)yStart, bm.bmWidth, bm.bmHeight,
  105.                        hMemDC, 0,0, SRCAND);
  106.  
  107.                 DeleteDC(hDC);
  108.                 DeleteDC(hMemDC);
  109.  
  110.                 OpenSound();
  111.                 StopSound();
  112.                 SetSoundNoise(nNoise++, 100);
  113.                 StartSound();
  114.                 for (nIndex=0; nIndex < 65535; nIndex++); /* pause      */
  115.  
  116.                 SendMessage( hWnd, WM_CLOSE, 0, 0L );
  117.                 }
  118.             break;
  119.  
  120.         case WM_CREATE:
  121.             srand((unsigned)GetTickCount());
  122.             break;
  123.  
  124.         case WM_DESTROY:
  125.             DeleteObject(hBitmap);
  126.             PostQuitMessage(0);
  127.             CloseSound();
  128.             StopSound();
  129.             KillTimer( hWnd, 1 );
  130.             break;
  131.  
  132.         default:
  133.             return (DefWindowProc(hWnd, iMessage, wParam, lParam));
  134.         }
  135.     return 0L;
  136. }
  137.  
  138.